/* - IFKitAttachListener -
 * Here we'll display the interface kit details as well as determine how many output
 * and input fields to display as well as determine the range of values for 
 * the output simulator slider
 *
 * Copyright 2007 Phidgets Inc.  
 * This work is licensed under the Creative Commons Attribution 2.5 Canada License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
 */

package listeners;

import com.phidgets.InterfaceKitPhidget;
import com.phidgets.PhidgetException;
import com.phidgets.event.AttachListener;
import com.phidgets.event.AttachEvent;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class IFKitAttachListener implements AttachListener {

    private JFrame m_appFrame;
    private JTextField m_attachedTxt;
    private JButton m_startButton;
    
    
    /** Creates a new instance of IFKitAttachListener */
    public IFKitAttachListener(JFrame appFrame, JTextField attachedTxt, JButton startButton)
    {
        m_appFrame = appFrame;
        m_attachedTxt = attachedTxt;
        m_startButton = startButton;
    }

    public void attached(AttachEvent ae)
    {
        try {
            InterfaceKitPhidget attached = (InterfaceKitPhidget)ae.getSource();
            m_attachedTxt.setText(Boolean.toString(attached.isAttached()));
            m_startButton.setEnabled(true);
        }
        catch (PhidgetException ex)
        {
            JOptionPane.showMessageDialog(m_appFrame, ex.getDescription(), "Phidget error " + ex.getErrorNumber(), JOptionPane.ERROR_MESSAGE);
        }
    }
    
}
